﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions.Assertions;
using FluentAssertions.Common;
using FluentAssertions.EventMonitoring;
using FluentAssertions.Formatting;
using FluentAssertions;
using LOMBARDISPICK.Domain.Services;
using Moq;
using LOMBARDISPICK.Tests.Infrastructure;
using LOMBARDISPICK.Domain.Services;
using System.Web.Mvc;

using IKVM.Runtime;
using IKVM;
using weka;
using weka.core;
using weka.experiment;
using weka.classifiers.evaluation;
using System.IO;



namespace LOMBARDISPICK.Tests.Controllers
{
	[TestClass]
	public class PredictionTests
	{
		INFLTeamsService NFLTeamService = DependencyResolver.Current.GetService<INFLTeamsService>();
		ITeamSeason_1985_2011Service TeamSeasonService = DependencyResolver.Current.GetService<ITeamSeason_1985_2011Service>();

        //[TestMethod]
        //public void TestPointsPerGameOffense()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.PointsPerGameOffense(50);
        //    decimal TopCase = PerdictionService.PointsPerGameOffense(40);
        //    decimal PositiveMidRange = PerdictionService.PointsPerGameOffense(27);
        //    decimal MiddleCase = PerdictionService.PointsPerGameOffense(17);
        //    decimal NegativeMidRange = PerdictionService.PointsPerGameOffense(10);
        //    decimal BottomCase = PerdictionService.PointsPerGameOffense(2);
        //    decimal BelowBottomCase = PerdictionService.PointsPerGameOffense(0);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}



        //[TestMethod]
        //public void TestPointsPerGameDefense()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.PointsPerGameDefense(5);
        //    decimal TopCase = PerdictionService.PointsPerGameDefense(10);
        //    decimal PositiveMidRange = PerdictionService.PointsPerGameDefense(17);
        //    decimal MiddleCase = PerdictionService.PointsPerGameDefense(21);
        //    decimal NegativeMidRange = PerdictionService.PointsPerGameDefense(30);
        //    decimal BottomCase = PerdictionService.PointsPerGameDefense(35);
        //    decimal BelowBottomCase = PerdictionService.PointsPerGameDefense(40);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}

        //[TestMethod]
        //public void PasserRating()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.PasserRating(165.5m);
        //    decimal TopCase = PerdictionService.PasserRating(158.3m);
        //    decimal PositiveMidRange = PerdictionService.PasserRating(125.5m);
        //    decimal MiddleCase = PerdictionService.PasserRating(79.0m);
        //    decimal NegativeMidRange = PerdictionService.PasserRating(60.0m);
        //    decimal BottomCase = PerdictionService.PasserRating(0);
        //    decimal BelowBottomCase = PerdictionService.PasserRating(-79.0m);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}

        //[TestMethod]
        //public void TurnoverDifferential()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.TurnoverDifferential(60);
        //    decimal TopCase = PerdictionService.TurnoverDifferential(40);
        //    decimal PositiveMidRange = PerdictionService.TurnoverDifferential(25);
        //    decimal MiddleCase = PerdictionService.TurnoverDifferential(0);
        //    decimal NegativeMidRange = PerdictionService.TurnoverDifferential(-10);
        //    decimal BottomCase = PerdictionService.TurnoverDifferential(-40);
        //    decimal BelowBottomCase = PerdictionService.TurnoverDifferential(-60);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}



        //[TestMethod]
        //public void redzonePercentageOffense()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.redzonePercentageOffense(90.00m);
        //    decimal TopCase = PerdictionService.redzonePercentageOffense(75.00m);
        //    decimal PositiveMidRange = PerdictionService.redzonePercentageOffense(50.00m);
        //    decimal MiddleCase = PerdictionService.redzonePercentageOffense(35.00m);
        //    decimal NegativeMidRange = PerdictionService.redzonePercentageOffense(25.00m);
        //    decimal BottomCase = PerdictionService.redzonePercentageOffense(15.00m);
        //    decimal BelowBottomCase = PerdictionService.redzonePercentageOffense(10.00m);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}



        //[TestMethod]
        //public void redZonePercentageDefense()
        //{
        //    //
        //    // Arrange
        //    var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

        //    //
        //    // Act
        //    decimal OverTopCase = PerdictionService.redZonePercentageDefense(15.00m);
        //    decimal TopCase = PerdictionService.redZonePercentageDefense(30.00m);
        //    decimal PositiveMidRange = PerdictionService.redZonePercentageDefense(40.00m);
        //    decimal MiddleCase = PerdictionService.redZonePercentageDefense(50.00m);
        //    decimal NegativeMidRange = PerdictionService.redZonePercentageDefense(65.00m);
        //    decimal BottomCase = PerdictionService.redZonePercentageDefense(75.00m);
        //    decimal BelowBottomCase = PerdictionService.redZonePercentageDefense(85.00m);

        //    //
        //    // Assert
        //    Assert.IsNotNull(TopCase);
        //    Assert.AreEqual(OverTopCase, 1);
        //    Assert.AreEqual(TopCase, 1);
        //    PositiveMidRange.Should().BeInRange(0, 1);
        //    Assert.AreEqual(MiddleCase, 0);
        //    NegativeMidRange.Should().BeInRange(-1, 0);
        //    Assert.AreEqual(BottomCase, -1);
        //    Assert.AreEqual(BelowBottomCase, -1);
        //}



		[TestMethod]
		public void testWeka()
		{
            String Winner = "Winner";
		    String RunnerUp = "RunnerUp";
    	    String No = "No";


            string TestPath = System.Web.HttpContext.Current.Server.MapPath(@"~/Controllers/newTest.arff");
            StreamReader streamReader = new StreamReader(TestPath);
            string TestText = streamReader.ReadToEnd();
            streamReader.Close();

            string TrainingPath = System.Web.HttpContext.Current.Server.MapPath(@"~/Controllers/newTraining.arff");
            streamReader = new StreamReader(TrainingPath);
            string TrainingText = streamReader.ReadToEnd();
            streamReader.Close();

            java.io.InputStream TrainingStream = new java.io.FileInputStream(TrainingText);
            java.io.InputStream TestStream = new java.io.FileInputStream(TestText);



            weka.core.converters.ArffLoader arffLoader = new weka.core.converters.ArffLoader();

            arffLoader.setSource(TrainingStream);
            Instances trainingDataInstances = arffLoader.getDataSet();
            arffLoader.setSource(TestStream);
            Instances testDataInstances = arffLoader.getDataSet();
            FastVector attValsSupperBowlWinners;
            attValsSupperBowlWinners = new FastVector();
			attValsSupperBowlWinners.addElement(Winner);
			attValsSupperBowlWinners.addElement(RunnerUp);
			attValsSupperBowlWinners.addElement(No);

            var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

            List<LOMBARDISPICK.Model.LPWekaPrediction> LPWekaResults = PerdictionService.LPWekaPrediction(trainingDataInstances, testDataInstances, attValsSupperBowlWinners, 2012);
            var test = LPWekaResults;

            //var PerdictionService = new LOMBARDISPICK.Domain.Services.PredictionService(NFLTeamService, TeamSeasonService);

            //LOMBARDISPICK.Model.LPCoefficient myLPCoefficientModel = new LOMBARDISPICK.Model.LPCoefficient();
			
            //myLPCoefficientModel.NFLTeamsID = 1;
            //myLPCoefficientModel.PasserRating = (decimal)158.3;
            //myLPCoefficientModel.PointsPerGameDefense = 0;
            //myLPCoefficientModel.PointsPerGameOffense = 74;
            //myLPCoefficientModel.redZonePercentageDefense = 0;
            //myLPCoefficientModel.redzonePercentageOffense = 100;
            //myLPCoefficientModel.TurnoverDifferential = 90;
            //myLPCoefficientModel.TimeOfPosession = 60;
            //myLPCoefficientModel.PassingYardsPerAttempt = 20;
            //myLPCoefficientModel.ThirdDownPercentage = 100;
            //myLPCoefficientModel.FourthDownPercentage = 100;
            //myLPCoefficientModel.Penalties = 0;
            //myLPCoefficientModel.PenaltyYards = 0;
            //myLPCoefficientModel.TimesSacked = 160;
            //myLPCoefficientModel.TimesSackedYards = 1600;
            //myLPCoefficientModel.QuarterbackHits = 320;
            //myLPCoefficientModel.OpponentTimeOfPosession = 0;
            //myLPCoefficientModel.OpponentPassingYardsPerAttempt = 0;
            //myLPCoefficientModel.OpponentPasserRating = 0;
            //myLPCoefficientModel.OpponentThirdDownPercentage = 0;
            //myLPCoefficientModel.OpponentFourthDownPercentage = 0;
            //myLPCoefficientModel.OpponentPenalties = 160;
            //myLPCoefficientModel.OpponentPenaltyYards = 1600;
            //myLPCoefficientModel.OpponentTimesSacked = 0;
            //myLPCoefficientModel.OpponentTimesSackedYards = 0;
            //myLPCoefficientModel.Punts = 0;
            //myLPCoefficientModel.OpponentPunts = 200;
            //myLPCoefficientModel.OpponentTurnoverDifferential = -80;


            //List<LOMBARDISPICK.Model.LPWekaPrediction> LPWeka = PerdictionService.CalculateWeka(2011, myLPCoefficientModel);

            //var test = LPWeka;
		}

	}

}